package com.hmy.infrastructure.manager;

import cn.hutool.json.JSONUtil;
import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.contract.bo.request.contract.ContractSignFinishedRequest;
import com.hmy.contract.bo.response.contract.ContractInfoResponse;
import com.hmy.contract.client.contract.ContractClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author seven.qi 齐胜南
 * @version 1.0
 * @description
 * @date 2023/12/28 19:19
 */

@Component
@Slf4j
public class ContractFeignClientManager {

    @Resource
    private ContractClient contractClient;


    public ContractInfoResponse signFinished(ContractSignFinishedRequest request) {
        log.info("ContractFeignClientManager.signFinished params:{}", JSONUtil.toJsonPrettyStr(request));
        FeignResult<ContractInfoResponse> response = null;
        response = contractClient.signFinished(request);
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(404000010);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        log.info("OrderFeignClientRpc.updateContractNo response:{}", JSONUtil.toJsonPrettyStr(response));
        return response.getData();
    }
}
